package userinput;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import data.DataPoint;
import data.TextTokenizer;

public class UserInput {
	
	public static RangeQuery getPointRangeQuery(){
		String input = null;
		String token1, token2 = null;
		int data1, data2;
		boolean point = false;
		//prompt user for input
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
	         input = br.readLine();
	         if(input==null){
	        	 return null;
	         }
	         else{
	        	 StringTokenizer st = new StringTokenizer (input, " ,");
	        	 
	        	 //tokenize the dimension input and create the query
	        	//token1
	        	 if(st.hasMoreElements()) 
	        		 token1 = st.nextToken();
	        	 else{
	        		 System.out.println("Error-No Input");
	        		 return null;
	        	 }
	        	//token2
	        	 if(st.hasMoreElements()){
	        		 token2 = st.nextToken(); //error check
	        	 }
	        	 else{
	        		 point=true; //only one value, so point = true
	        	 }
	        	 
	        	 //create RangeQuery data type
        		 //convert data1
	        	 try{
	        		 data1 = Integer.parseInt(token1);
	        		 
	        		//convert data2
	        		 if(point==false){	 
		        		 try{
		        			 data2 = Integer.parseInt(token2);
		        			 return new RangeQuery(data1,data2); //range
		        		 }catch(Exception e){
		        			 return new RangeQuery(data1); //point
		        		 }	 
	        		 }
	        		 else{
	        			 return new RangeQuery(data1); //point
	        		 }
	        	 }catch (Exception e){
	        		 System.out.println("Error-Bad input");
	    	         return null;
	        	 }
	         }
	      } catch (IOException ioe) {
	    	  System.out.println("Error-Bad input");
	         return null;
	      }
	}
	
	public static void printInputMenu(){
		System.out.println("---------------------------------------------------------");
		System.out.print("Please enter a point <a> or a range <a,b> for your query: ");
	}
}
